//
//  BCTimerHandler.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/5.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCTimerHandler.h"

@implementation BCTimerHandler

- (instancetype)init
{
    self = [super init];
    if (self) {
        _timeInterval = 1.0;
    }
    return self;
}

- (void)start {
    [self stop];
    _timer = [NSTimer scheduledTimerWithTimeInterval:self.timeInterval target:self selector:@selector(timerAction) userInfo:nil repeats:true];
    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
}
//
- (void)timerAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(timerHandlerRepeatsAction)]) {
        [self.delegate timerHandlerRepeatsAction];
    }
}

- (void)stop {
    if (!_timer) {
        [_timer invalidate];
        _timer = nil;
    }
}

@end
